package com.example.demo.controller;

import com.example.demo.base.ExecResult;
import com.example.demo.service.ExecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ExecController {

    @Autowired
    private ExecService execService;


    @PostMapping("/call/linux/command")
    public ExecResult callCommand(@RequestParam("command") String command) {
        ExecResult execResult = execService.execCommand(execService.parseCommand(command));
        if (execResult.getExitCode() == 0) {
            System.out.println("success");
        }else{
            System.out.println("fail");
        }
        return execResult;
    }
}
